home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / PRGDev.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  9.7 KB  |  351 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PRGDev.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef PRGDEV_H
  11. #define PRGDEV_H
  12.  
  13. #ifndef SLGRDEF_H
  14. #include "SLGrDef.h"
  15. #endif
  16.  
  17. #ifndef SLGDEV_H
  18. #include "SLGDev.h"
  19. #endif
  20.  
  21. #ifndef FWGCONST_H
  22. #include "FWGConst.h"
  23. #endif
  24.  
  25. #ifndef FWPOINT_H
  26. #include "FWPoint.h"
  27. #endif
  28.  
  29. #ifndef FWCOLOR_H
  30. #include "FWColor.h"
  31. #endif
  32.  
  33. #ifndef PRSHATTR_H
  34. #include "PRShAttr.h"
  35. #endif
  36.  
  37. #ifndef PRGRREF_H
  38. #include "PRGrRef.h"
  39. #endif
  40.  
  41. #if defined(FW_BUILD_WIN) && !defined(FWGDIOBJ_H)
  42. #include "FWGDIObj.h"
  43. #endif
  44.  
  45. #ifdef SelectFont
  46. #undef SelectFont    // Macro in Windowsx.h
  47. #endif
  48.  
  49. // ----- Foundation Includes -----
  50.  
  51. #ifndef FWREFCNT_H
  52. #include "FWRefCnt.h"
  53. #endif
  54.  
  55. // ----- OpenDoc Includes -----
  56.  
  57. #ifndef SOM_ODCanvas_xh
  58. #include <Canvas.xh>
  59. #endif
  60.  
  61. #ifndef SOM_ODTransform_xh
  62. #include <Trnsform.xh>
  63. #endif
  64.  
  65. //========================================================================================
  66. //    Forward Declarations
  67. //========================================================================================
  68.  
  69. class    ODShape;
  70. class    FW_CPoint;
  71. class    FW_CRect;
  72. class    FW_CPlatformRect;
  73. class    FW_CPlatformPoint;
  74.  
  75. struct    FW_SGraphicContext;
  76.  
  77. //========================================================================================
  78. //    Shape Types
  79. //========================================================================================
  80.  
  81. enum FW_EPrivShapeCategories
  82. {
  83. #ifdef FW_BUILD_MAC
  84.     FW_kLineShape,            // Line
  85.     FW_kGeometricShape,        // Rect, Oval, Arc, RoundRect, Region
  86.     FW_kTypographicShape,    // Text
  87.     FW_kImageShape            // Bitmap, Picture
  88. #endif
  89. #ifdef FW_BUILD_WIN
  90.     FW_kGeometricShapeWithInvert,    // Rect, Region
  91.     FW_kGeometricShape,                // Line, RoundRect, Oval, Arc
  92.     FW_kTypographicShape,            // Text
  93.     FW_kImageShape                    // Bitmap, Picture
  94. #endif
  95. };
  96.  
  97.  
  98. //========================================================================================
  99. //    Forward declarations
  100. //========================================================================================
  101.  
  102. struct FW_SGraphicContext;
  103.  
  104. //========================================================================================
  105. //    struct FW_SPrivDeviceState
  106. //========================================================================================
  107.  
  108. struct FW_SPrivDeviceState
  109. {
  110. #ifdef FW_BUILD_WIN
  111.     POINT                    fWindOrg;
  112.     WORD                    fMapMode;
  113. #endif
  114. #ifdef FW_BUILD_MAC
  115.     // ----- if our port is not the current port fPreviousPlatformCanvas != NULL -----
  116.     ODPlatformCanvas        fPreviousPlatformCanvas;
  117.     
  118.     // ----- if our port was the current port (fPreviousPlatformCanvas==NULL) save its state below -----
  119.     ODRgnHandle                fClip;
  120.     Point                    fOrigin;
  121.     
  122.     FW_Boolean                fSuspended;
  123.  
  124.     FW_SGraphicContext*        fSavedContext;
  125. #endif
  126. };
  127.  
  128. //========================================================================================
  129. //    struct FW_SPrivSuspendResumeState
  130. //========================================================================================
  131.  
  132. #ifdef FW_BUILD_WIN
  133. struct FW_SPrivSuspendResumeState
  134. {
  135.     int                        fSavedDC;
  136.     FW_SGraphicContext*        fSavedContext;
  137. };
  138. #endif
  139.  
  140. #ifdef FW_BUILD_MAC
  141. #define FW_SPrivSuspendResumeState    FW_SPrivDeviceState
  142. #endif
  143.  
  144. //========================================================================================
  145. //    class FW_CPrivGraphicsDevice
  146. //========================================================================================
  147.  
  148. class    FW_CPrivGraphicsDevice : public FW_CPrivGrRefObj
  149. {
  150. //---------------------------------------------------------------------------------------
  151. //    Constructor/Destructor
  152. //
  153. public:
  154.     FW_DECLARE_AUTO(FW_CPrivGraphicsDevice)
  155.  
  156.                             FW_CPrivGraphicsDevice(ODCanvas* odCanvas);
  157.                             FW_CPrivGraphicsDevice(ODPlatformCanvas platformCanvas);
  158.     
  159.     virtual                 ~FW_CPrivGraphicsDevice();
  160.  
  161. //---------------------------------------------------------------------------------------
  162. //    API
  163. //
  164. public:
  165.     ODPlatformCanvas        GetPlatformCanvas() const;
  166.     operator                 ODPlatformCanvas() const;
  167.  
  168.     ODCanvas*                 GetODCanvas() const;
  169.  
  170.     FW_SPrivDeviceState*    OpenDevice(Environment *ev, FW_SGraphicContext* context);
  171.     void                     CloseDevice(Environment *ev, FW_SPrivDeviceState* deviceState);
  172.     
  173.     ODRgnHandle             GetClip() const;                                            // return a copy
  174.     void                    GetClipRect(FW_CPlatformRect& clipRect) const;
  175.  
  176.     void                     SetClip(Environment* ev, ODRgnHandle clipRegion);                            // Use a copy
  177.     void                    SetClipRect(const FW_CPlatformRect& clipRect);
  178.     void                    IntersectClipRect(Environment* ev, const FW_CPlatformRect& clipRect);
  179.  
  180.     void                    SetOrigin(Environment* ev, FW_CPlatformPoint origin);
  181.     
  182.     FW_SPrivDeviceState*    GetState();
  183.     
  184.     FW_SPrivSuspendResumeState*    Suspend();
  185.     void                    Resume(FW_SPrivSuspendResumeState *suspendResumeState);
  186.                                                         
  187.     void                    CanvasChanged(Environment *ev, ODCanvas* odCanvas);
  188.     void                    MappingChanged(Environment* ev);
  189.     
  190.     // ----- Return the resolution in dpi -----
  191.     FW_CPoint                GetResolution() const;
  192.     void                    SetResolution(FW_Fixed x, FW_Fixed y);
  193.     
  194.     void                    UpdateOriginForContext(Environment* ev);
  195.                                      
  196. //----------------------------------------------------------------------------------------
  197. //    Data Members
  198. //
  199. protected:
  200.     ODCanvas*                 fODCanvas;            // Might be NULL
  201.     ODPlatformCanvas         fPlatformCanvas;
  202.     
  203.     short                    fOpenDeviceCount;
  204.     
  205.     FW_CPoint                 fResolution;
  206.  
  207.     FW_Boolean                fSuspended;
  208.     
  209.     FW_SGraphicContext*        fContext;
  210.     
  211. //----------------------------------------------------------------------------------------
  212. //    Platform Specific API
  213. //
  214. #ifdef FW_BUILD_WIN
  215. public:
  216.     void                    SelectFont(const FW_HFont font, FW_Boolean scale);
  217.  
  218.     FW_Boolean                IsMetaFileCanvas() const;
  219.  
  220.     // ----- Settings -----    
  221.     void                    SelectInkAndFont(const FW_HInk ink, 
  222.                                             const FW_HFont font);
  223.     FW_Boolean                SelectInkAndStyle(const FW_HInk ink, 
  224.                                             const FW_HStyle style,
  225.                                             FW_EPrivShapeCategories shapeType, 
  226.                                             FW_ERenderVerbs renderVerb);
  227.                                             
  228.     void                    SetTextColor(COLORREF textColor);    
  229.     void                    SetBkColor(COLORREF bkColor);
  230.     
  231. protected:
  232.     // ----- We don't bother doing any caching for those, they should be pretty fast -----
  233.     void                    SetDrawingMode(int drawingMode)
  234.                                 {::SetROP2(fPlatformCanvas, drawingMode);}
  235.     void                    SetBkMode(int bkMode)
  236.                                 {::SetBkMode(fPlatformCanvas, bkMode);}
  237. #endif
  238. #ifdef FW_BUILD_MAC                                    
  239. public:
  240.     // ----- Settings -----
  241.     void                    SelectInk(const FW_HInk ink, 
  242.                                 FW_EPrivShapeCategories shapeCategory, 
  243.                                 FW_ERenderVerbs renderVerb);
  244.     void                    SelectStyle(const FW_HStyle style, 
  245.                                 FW_TransferModes transferMode,
  246.                                 FW_Boolean& styleIsDash,
  247.                                 FW_Boolean& styleIsHairline);
  248.     void                    SelectFont(const FW_HFont font, 
  249.                                 FW_Boolean scale);
  250.  
  251.     void                    SetInGrafPort();
  252.     void                    ResetSettings();
  253.     
  254.     // Values for fChangeFlag
  255.     enum
  256.     {
  257.         FW_kForeColorChanged     =    0x0001,
  258.         FW_kBackColorChanged    =    0x0002,
  259.         FW_kHiliteColorChanged    =    0x0004,
  260.         FW_kPatternChanged        =    0x0008
  261.     };
  262.  
  263.     void                    SetForeColor(const FW_CColor& foreColor)
  264.                                 {fForeColor = foreColor; fChangeFlag |= FW_kForeColorChanged;}
  265.     void                    SetBackColor(const FW_CColor& backColor)
  266.                                 {fBackColor = backColor; fChangeFlag |= FW_kBackColorChanged;}
  267.     void                    SetHiliteColor(const FW_CColor& hiliteColor)
  268.                                 {fHiliteColor = hiliteColor; fChangeFlag |= FW_kHiliteColorChanged;}
  269.     void                    SetPattern(const FW_HPattern pattern);
  270.     void                    SetPenSize(short hPenSize, short vPenSize)
  271.                                 {fHPenSize = hPenSize; fVPenSize = vPenSize;}
  272.     void                    SetFontID(short fontID)
  273.                                 {fFontID = fontID;}
  274.     void                    SetFontSize(short fontSize)
  275.                                 {fFontSize = fontSize;}
  276.     void                    SetFontStyle(Style fontStyle)
  277.                                 {fFontStyle = fontStyle;}
  278.     void                    SetPenMode(short penMode)
  279.                                 {fPenMode = penMode;}
  280.     void                    SetTextMode(short textMode)
  281.                                 {fTextMode = textMode;}
  282.     
  283. private:                            
  284.     void                    MacBeginPostScriptClip(Environment* ev, RgnHandle rgn);
  285.     void                    MacEndPostScriptClip();
  286. #endif
  287.  
  288. //----------------------------------------------------------------------------------------
  289. //    Platform Specific Data Members
  290. //
  291. #ifdef FW_BUILD_WIN
  292. public:
  293.     // ----- Settings -----
  294.     COLORREF                fTextColor;
  295.     COLORREF                fBkColor;
  296.     FW_CPlatformPoint        fPenSize;    // Used for frame with brush
  297.  
  298.     // ----- Brush/Pen/Font -----
  299.     FW_CPrivGDIPen            fGDIPen;
  300.     FW_CPrivGDIBrush        fGDIBrush;
  301.     FW_CPrivGDIFont            fGDIFont;
  302. #endif
  303. #ifdef FW_BUILD_MAC
  304. public:
  305.     // ----- Device Settings -----
  306.     FW_CColor                 fForeColor;
  307.     FW_CColor                fBackColor;
  308.     FW_CColor                fHiliteColor;
  309.     FW_PPrivPattern            fPattern;
  310.     short                    fHPenSize;
  311.     short                    fVPenSize;
  312.     short                    fFontID;
  313.     short                    fFontSize;
  314.     Style                    fFontStyle;
  315.     short                    fPenMode;
  316.     short                    fTextMode;
  317.  
  318. private:
  319.     unsigned short            fChangeFlag;
  320.  
  321.     // ----- PostScript clipping
  322.     FW_Boolean                fMacPostScriptClip;
  323. #endif
  324. };
  325.  
  326. //---------------------------------------------------------------------------------------
  327. //    FW_CPrivGraphicsDevice::GetODCanvas
  328. //---------------------------------------------------------------------------------------
  329. inline ODCanvas* FW_CPrivGraphicsDevice::GetODCanvas() const
  330. {
  331.     return fODCanvas;
  332. }
  333.  
  334. //---------------------------------------------------------------------------------------
  335. //    FW_CPrivGraphicsDevice::GetPlatformCanvas
  336. //---------------------------------------------------------------------------------------
  337. inline ODPlatformCanvas FW_CPrivGraphicsDevice::GetPlatformCanvas() const
  338. {
  339.     return fPlatformCanvas;
  340. }
  341.  
  342. //---------------------------------------------------------------------------------------
  343. //    FW_CPrivGraphicsDevice::operator ODPlatformCanvas
  344. //---------------------------------------------------------------------------------------
  345. inline FW_CPrivGraphicsDevice::operator ODPlatformCanvas() const
  346. {
  347.     return fPlatformCanvas;
  348. }
  349.  
  350. #endif
  351.